package wang.yangziqing.app_kotlin.base

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.runOnUiThread
import org.jetbrains.anko.toast

/**
 * Created by Administrator on 2017/11/29.
 * 所有Fragment的基类
 */
abstract class BaseFragment:Fragment(),AnkoLogger {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        init()
    }


    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return  initView()
    }



    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initListener()
        initData()

    }

    /**
     * 获取布局的view
     */
    abstract fun initView(): View?
    open protected fun init() { }

    open  protected fun initData() { }

    open protected fun initListener() { }
@Suppress("unused")
    protected  fun MyToast(msg:String){
        context.runOnUiThread { toast(msg) }

    }

}